package cn.itsource.controller;

import cn.itsource.domain.User;
import cn.itsource.exception.BusinessException;
import cn.itsource.service.IUserService;
import cn.itsource.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SystemController {

    @Autowired
    private IUserService userService;

    @PostMapping("/login")
    public R login(User user){
        try {
            String token = userService.login(user);
            return R.ok("登陆成功",token);
        } catch (BusinessException e) {
            return R.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return R.fail("系统繁忙，请稍后重试");
        }
    }
}
